package com.example.yjhero.safeapp.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.example.yjhero.safeapp.R;
import com.example.yjhero.safeapp.base.BaseSetUpActivity;
import com.example.yjhero.safeapp.utils.DialogUtil;

public class SetUp3Activity extends BaseSetUpActivity {
    private EditText mInputphone;
    private Button mBtn_addcontact;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup3);
        initview();
        initData();
    }

    @Override
    public void showNext() {
        String safephone=mInputphone.getText().toString().trim();
        if(TextUtils.isEmpty(safephone)){
            Toast.makeText(SetUp3Activity.this,"请输入安全码!",Toast.LENGTH_SHORT).show();
            return;
        }
        SharedPreferences.Editor editor=sp.edit();
        editor.putString("safephone",safephone);
        editor.commit();
        startActivityAndFinishSelf(SetUp4Activity.class);
    }

    @Override
    public void showPre() {
        startActivityAndFinishSelf(SetUp2Activity.class);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data!=null){
            String phone=data.getStringExtra("phone");
            mInputphone.setText(phone);
        }
    }

    private void initData() {
        mBtn_addcontact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(SetUp3Activity.this,ContactSelectActivity.class),0);
            }
        });
    }

    private void initview() {
        ((RadioButton)findViewById(R.id.rb_third)).setChecked(true);
        mBtn_addcontact=findViewById(R.id.btn_addcontact);
        mInputphone=findViewById(R.id.et_inputphone);
        String safephone=sp.getString("safephone",null);
        if(!TextUtils.isEmpty(safephone)){
            mInputphone.setText(safephone);
        }
    }
}
